//
//  SportNumberList.m
//  PlayBall
//
//  Created by Huawen Liu on 12-7-29.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "JddSportNumberList.h"

@implementation JddSportNumberList
@synthesize sportList;

-(id)init{
    self = [super init];
    
    if (self) {
        self.sportList = [NSMutableArray array];

    }
    
    return self;
}

-(void)removeAtIndexes:(NSInteger)indexes{
    sportList = [NSMutableArray arrayWithArray:sportList];
    [sportList removeObjectAtIndex:indexes];
}

//-(void)AddNumber:(SportNumber *)number{
//    NSArray *numarray = [NSArray arrayWithArray: number.teamArray];
////    for (int i = 0;i<[sportList count]; ++i) {
////        SportNumber *number2 = [sportList objectAtIndex:i];
////        if ([number.code isEqualToString:number2.code]) {
////            [number2.teamArray addObject:[number.teamArray objectAtIndex:0]];
////            return;
////        }
////    }
//    [sportList addObject:number];
//}

-(BOOL)BallHasNumber:(JddSportNumber*)number{
    for (int i = 0;i<[sportList count]; ++i) {
        JddSportNumber *number2 = [sportList objectAtIndex:i];
        if ([number.code isEqualToString:number2.code]) {
            for (int a = 0; a<[number2.teamArray count]; ++a) {
                if ([[number.teamArray objectAtIndex:0] isEqualToString:[number2.teamArray objectAtIndex:a]]) {
                    [number2.teamArray removeObjectAtIndex:a];
                    if ([number2.teamArray count]==0) {
                        [sportList removeObjectAtIndex:i];
                    }
                    return NO;
                }
            }
            [number2.teamArray addObject:[number.teamArray objectAtIndex:0]];
            return YES;
        }
    }
    [sportList addObject:number];
    return YES;
}


-(void)addBallNumberBeforeRemove:(JddSportNumber*)number{
    NSMutableArray *sp = [NSMutableArray arrayWithArray:sportList];
    for (JddSportNumber *number2 in sportList) {
        if ([number.code isEqualToString:number2.code]) {
            [sp removeObject:number2];
        }
    }
    [sp addObject:number];
    sportList = sp;
}

-(void)removeBallNumber:(JddSportNumber*)number
{
    NSMutableArray *sp = [NSMutableArray arrayWithArray:sportList];
    for (JddSportNumber *number2 in sportList) {
        if ([number.code isEqualToString:number2.code]) {
            [sp removeObject:number2];
        }
    }
    sportList = sp;
}


@end
